package com.xtkj.superclub_friendscircle.interceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * 项目名称：superclub
 * 类 名 称：FeignInterceptor
 * 类 描 述：Feign拦截器，解决请求头丢失问题
 * 创建时间：2020/1/4 15:02
 * 创 建 人：xiezhiyan
 */
@Configuration
public class FeignInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        ServletRequestAttributes attributes=(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        //添加请求头
        requestTemplate.header("token", request.getHeader("token"));
    }
}